﻿using System;
using System.Windows;
using System.Windows.Media;
using _3DTicTacToe.Core;

namespace _3DTicTacToe
{
    partial class GameOverWindow : Window
    {
        private readonly TicTacToeGame _game;

        public GameOverWindow()
        {
            InitializeComponent();
        }

        public GameOverWindow(GameOverEventArgs args, TicTacToeGame game)
            : this()
        {
            _game = game;
            if (args.IsDraw)
            {
                drawGrid.Visibility = Visibility.Visible;
            }
            else
            {
                winGrid.Visibility = Visibility.Visible;

                winningPlayerNameRun.Foreground = new SolidColorBrush(args.WinningPlayer.Color);
                losingPlayerNameRun.Foreground = new SolidColorBrush(args.LosingPlayer.Color);

                winningPlayerNameRun.Text = args.WinningPlayer.Name + " ";
                losingPlayerNameRun.Text = args.LosingPlayer.Name + " ";

                firstCP.Content = string.Format("({0} {1} {2})", args.WinningCoords[0], args.WinningCoords[1],
                                                args.WinningCoords[2]);
                secondCP.Content = string.Format("({0} {1} {2})", args.WinningCoords[3], args.WinningCoords[4],
                                                args.WinningCoords[5]);
                thirdCP.Content = string.Format("({0} {1} {2})", args.WinningCoords[6], args.WinningCoords[7],
                                                args.WinningCoords[8]);
                fourthCP.Content = string.Format("({0} {1} {2})", args.WinningCoords[9], args.WinningCoords[10],
                                                args.WinningCoords[11]);
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            new StartWindow().Show();
            Close();
        }

        private void rematchButton_Click(object sender, RoutedEventArgs e)
        {
            new GameWindow(new TicTacToeGame(_game.PlayerTwo, _game.PlayerOne)).Show(); //exchange players
            Close();
        }
    }
}
